/** @file math.h
 *
 *  @author Dongryeol Lee (drselee@gmail.com)
 */

#ifndef CORE_MATH_MATH_H
#define CORE_MATH_MATH_H

#include <algorithm>

namespace core {
namespace math {
template<typename T>
bool ApproxEqual(T a, T b) {
  T diff = a - b;
  diff = (diff < static_cast<T>(0)) ? -diff : diff;
  return diff <= 0.01 * std::max<T>(fabs(a), fabs(b));
}

template<typename T1, typename T2>
void scaled_add(double scale_in, const T1 &v1, T2 *v2_out) {
  for(int i = 0; i < v1.size(); i++) {
    (*v2_out)[i] += scale_in * v1[i];
  }
}
}
}

#endif
